package map.asteroids;

import logic.nodes.nodeSettings.Settings;

import com.jme.math.Vector3f;

public class AsteroidFieldProperties extends Settings {
	
	public static final String MINRES = "minRes";
	public static final String MAXRES = "maxRes";
	public static final String MIN_SIZE = "minSize";
	public static final String MAX_SIZE = "maxSize";
	public static final String MIN_DIST = "minDist";
	public static final String MAX_DIST = "maxDist";
	public static final String MIN_DIST_LOC = "minDistLoc";
	public static final String MAX_DIST_LOC = "maxDistLoc";
	public static final String MIN_FIELD_LENGTH = "minFieldLength";
	public static final String MAX_FIELD_LENGTH = "maxFieldLength";
	public static final String MIN_FIELD_WIDTH = "minFieldWidth";
	public static final String MAX_FIELD_WIDTH = "maxFieldWidth";
	public static final String MIN_FIELD_HEIGHT = "minFieldHeight";
	public static final String MAX_FIELD_HEIGHT = "maxFieldHeight";
	public static final String CENTER = "center";
	public static final String AMOUNT = "asteroidAmount";
	public static final String FIELDPATH = "fieldName";
	
	public AsteroidFieldProperties(Settings settings) {
		super(settings);
	}
	
	public float getMinSize() { return Float.valueOf(getValueOf(MIN_SIZE)).floatValue(); }
	
	public float getMaxSize() { return Float.valueOf(getValueOf(MAX_SIZE)).floatValue(); }
	
	public float getMinDist() { return Float.valueOf(getValueOf(MIN_DIST)).floatValue(); }
	
	public float getMaxDist() { return Float.valueOf(getValueOf(MAX_DIST)).floatValue(); }
	
	public float getMinDisLoc() { return Float.valueOf(getValueOf(MIN_DIST_LOC)).floatValue(); }
	
	public float getMaxDisLoc() { return Float.valueOf(getValueOf(MAX_DIST_LOC)).floatValue(); }
	
	public float getMinFieldLength() { return Float.valueOf(getValueOf(MIN_FIELD_LENGTH)).floatValue(); }
	
	public float getMaxFieldLength() { return Float.valueOf(getValueOf(MAX_FIELD_LENGTH)).floatValue(); }
	
	public float getMinFieldWidth() { return Float.valueOf(getValueOf(MIN_FIELD_WIDTH)).floatValue(); }
	
	public float getMaxFieldWidth() { return Float.valueOf(getValueOf(MAX_FIELD_WIDTH)).floatValue(); }
	
	public float getMinFieldHeight() { return Float.valueOf(getValueOf(MIN_FIELD_HEIGHT)).floatValue(); }
	
	public float getMaxFieldHeight() { return Float.valueOf(getValueOf(MAX_FIELD_HEIGHT)).floatValue(); }
	
	public int getMinRes() {
		try { return Integer.valueOf(getValueOf(MINRES)).intValue(); }
		catch(Exception e) { return 0; }
	}
	
	public int getMaxRes() {
		try { return Integer.valueOf(getValueOf(MAXRES)).intValue(); }
		catch(Exception e) { return 0; }
	}
	
	public boolean isResourceField() { return getMinRes() > 0f; }
	
	public Vector3f getCenter() { return createVector(CENTER); }
	
	private Vector3f createVector(String vectorString) {
		float x = Float.valueOf(getValueOf(vectorString + "X")).floatValue();
		float y = Float.valueOf(getValueOf(vectorString + "Y")).floatValue();
		float z = Float.valueOf(getValueOf(vectorString + "Z")).floatValue();
		return new Vector3f(x, y, z);
	}
	
	public Vector3f getStartPoint() {
		Vector3f length = Vector3f.UNIT_X.mult(getMaxFieldLength() / 2);
		Vector3f width = Vector3f.UNIT_Z.mult(getMaxFieldWidth() / 2);
		Vector3f height = Vector3f.UNIT_Y.mult(getMaxFieldHeight() / 2);
		return getCenter().subtract(length).subtract(width).subtract(height);
	}
	
	public int getAsteroidAmount() { return Integer.valueOf(getValueOf(AMOUNT)).intValue(); }
	
	public void setAsteroidAmount(int amount) { addOption(AMOUNT, amount + ""); }
	
	public String getFieldPath() { return getValueOf(FIELDPATH); }
	
	public void setFieldPath(String fieldPath) { addOption(FIELDPATH, fieldPath); }
}